﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using LuaCEGUI.XML;
using LuaCEGUI.FormBuilder;

namespace test
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [MTAThread]
        static int Main(string[] args)
        {
            /*
            if (Directory.Exists("/Program Files/wmssystem/XML/"))
            {
            }
            else
            {
                Directory.CreateDirectory("/Program Files/wmssystem/XML/");
            }
            FileStream fs = new FileStream("/Program Files/wmssystem/XML/order.xml", FileMode.Create);
            StreamWriter fw = new StreamWriter(fs);
            string str;
            str = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Form Name=\"order\" Location=\"10,10\" Size=\"400,400\" Text=\"MainFormText\"><Label Name=\"StockID\" Text=\"Stock_ID\" Location=\"30,30\" Size=\"50,50\" /><Label Name=\"StockName\"  Text=\"Stock_Name\" Location=\"10,70\" Size=\"50,50\" /><TextBox Name=\"Test\" Text=\"Test Text Box\" Location=\"10,200\" Size=\"200,50\" /><Button Name=\"Submit\" Text=\"Submit\" Location=\"10,260\" Size=\"200,50\" EventHandler=\"test\" WithValue=\"Test\"/></Form>";
            fw.Write(str);
            fw.Close();
            fs.Close();
            */
            string path = null;
            if (System.IO.File.Exists("/Program Files/wmssystem/XML/tmp/" + args[0].ToString() + ".xml"))
            {
                path = "/Program Files/wmssystem/XML/tmp/" + args[0].ToString() + ".xml";
            }
            else
            {
                path = "/Program Files/wmssystem/XML/" + args[0].ToString() + ".xml";
            }

            Console.WriteLine("DBG:I am trying to build a Form from XML:{0}", path);
            try
            {
                FormBuilder fb = new FormBuilder(path);
                fb.RunForm();
                return 0;
            }
            catch(Exception e)
            {
                Console.WriteLine("DBG:Error while loading XML file.path = {0} ,message : {1}",path,e.Message);
                return 2;
            }
            
            
        }
        
    }
}